package com.water.camera.fragment;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.databinding.DialogProgressLoadingBinding;
import com.water.camera.util.Utils;

public class ProgressLoadingDlg extends FullScreenDlg {

    DialogProgressLoadingBinding binding;
    int max = 0, progress = 0;
    String msg;

    public ProgressLoadingDlg setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = DialogProgressLoadingBinding.inflate(inflater, container, false);
        if (max != 0) {
            binding.bar.setMax(max);
        }
        if (!TextUtils.isEmpty(msg)) {
            binding.msg.setText(msg);
        }
        if (progress != 0) {
            binding.bar.setProgress(progress);
            binding.tv.setText(progress + "/" + binding.bar.getMax());
        }
        return binding.getRoot();
    }

    @Override
    protected int getWidth() {
        return (int) (Utils.getScreenWidth() * 0.8);
    }

    @Override
    protected int getHeight() {
        return ViewGroup.LayoutParams.WRAP_CONTENT;
    }

    public ProgressLoadingDlg setMax(int max) {
        if (binding == null) {
            this.max = max;
            return this;
        }
        binding.bar.setMax(max);
        return this;
    }

    public void setProgress(int p) {
        if (binding == null) {
            this.progress = p;
            return;
        }
        binding.bar.setProgress(p);
        binding.tv.setText(p + "/" + binding.bar.getMax());
    }
}
